<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="like">like</button>
    <button id="price">price</button>
    <script>
        var like = document.getElementById("like");
        var price = document.getElementById("price");
        var sales = [
            {name:"df1",like:80,price:200},
            {name:"df2",like:110,price:500},
            {name:"df3",like:60,price:300},
        ]
        function df (arr,value){
            if(Array.isArray(arr)){
                var res = arr.sort((a,b)=>{
                    return a[value]-b[value]
                })
                return res;
            }else{
                return null;
            }
        }
       
        like.onclick=function(){
            console.log(df(
                sales,"like"
            ))
        }
        price.onclick=function(){
            console.log(df(
                sales,"price"
            ))
        }
    </script>
</body>
</html>